<template>
  <el-switch
    v-model="searchValue"
    :active-value="config.activeValue !== undefined ? config.activeValue : true"
    :inactive-value="
      config.inactiveValue !== undefined ? config.inactiveValue : false
    "
    :disabled="config.disabled"
    :size="config.size || 'default'"
    :inline-prompt="config.inlinePrompt"
    :active-color="config.activeColor"
    :inactive-color="config.inactiveColor"
    @change="handleChange"
  ></el-switch>
</template>

<script setup>
import { computed } from "vue";
const props = defineProps(["model", "config"]);
const emit = defineEmits(["update"]);

const searchValue = computed({
  get() {
    return props.model;
  },
  set(value) {
    emit("update", props.config, value);
  },
});

// 处理开关变化事件
const handleChange = (value) => {
  if (props.config.onChange) {
    props.config.onChange(value);
  }
};
</script>

<style scoped>
/* 可以根据需要添加自定义样式 */
</style>
